/**
 * 初始化吊顶的 Help，并判断要不要展示小蓝点
 */

import docs from 'utils/docs';
import { getFeature } from 'utils/features';

import Solution from './solution';
// import OpenApi from './openApi';
// eslint-disable-next-line import/no-cycle
import Guide from './guide';
import intl from '../../../locale';

export default function (options = {}) {
  const { showGuide } = options;
  const helpList = [
    {
      trigger: 'onClick',
      title: intl.get({
        id: 'code-assets.initNavigation.initHelp.HelpCenter',
        defaultMessage: '帮助中心',
      }),
      redirectUrl: docs('welcomeToCodeup'),
      action: 'redirect',
    },

    {
      trigger: 'onClick',
      title: intl.get({
        id: 'code-assets.initNavigation.initHelp.UpdateLogs',
        defaultMessage: '更新日志',
      }),
      redirectUrl: docs('updateLogs'),
      action: 'redirect',
    },
  ];

  helpList.push({
    trigger: 'onClick',
    title: <Solution />,
    action: 'redirect',
    redirectUrl: docs('solution'),
  });

  const dom = document.querySelector('.codeUp-guide');
  if (dom && showGuide) {
    helpList.push({
      trigger: 'onClick',
      title: <Guide />,
      action: 'custom',
      plugin: () => ({ boot: () => {} }),
    });
  }

  helpList.push({
    trigger: 'onClick',
    title: '工单支持',
    action: 'redirect',
    redirectUrl: 'https://selfservice.console.aliyun.com/ticket/category/rdc/today',
  });

  if (!getFeature('vpc.nav.helpRegister')) {
    window.TB_NAVIGATION.Help.register(helpList);
  } else {
    window.TB_NAVIGATION.Help.register([
      {
        trigger: 'onClick',
        title: intl.get({
          id: 'code-assets.initNavigation.initHelp.HelpCenter',
          defaultMessage: '帮助中心',
        }),
        redirectUrl: docs('welcomeToCodeup'), // TODO 专有云环境URL待确认
        action: 'redirect',
      },
    ]);
  }

  // if (isAliyunDomain) {
  //   window.TB_NAVIGATION.Help.registerCustomArea([
  //     {
  //       element: <OpenApi />,
  //       trigger: 'onClick',
  //       action: 'custom',
  //       plugin: () => ({ boot: () => {} }),
  //     },
  //   ]);
  // }
}
